<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>select.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_ui_select.js.html">select.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2007 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview A class that supports single selection from a dropdown menu,
<a name="line17"></a> * with semantics similar to the native HTML &lt;code&gt;&amp;lt;select&amp;gt;&lt;/code&gt;
<a name="line18"></a> * element.
<a name="line19"></a> *
<a name="line20"></a> * @author attila@google.com (Attila Bodis)
<a name="line21"></a> * @see ../demos/select.html
<a name="line22"></a> */
<a name="line23"></a>
<a name="line24"></a>goog.provide(&#39;goog.ui.Select&#39;);
<a name="line25"></a>
<a name="line26"></a>goog.require(&#39;goog.a11y.aria&#39;);
<a name="line27"></a>goog.require(&#39;goog.a11y.aria.Role&#39;);
<a name="line28"></a>goog.require(&#39;goog.a11y.aria.State&#39;);
<a name="line29"></a>goog.require(&#39;goog.asserts&#39;);
<a name="line30"></a>goog.require(&#39;goog.events.EventType&#39;);
<a name="line31"></a>goog.require(&#39;goog.ui.Component.EventType&#39;);
<a name="line32"></a>goog.require(&#39;goog.ui.ControlContent&#39;);
<a name="line33"></a>goog.require(&#39;goog.ui.MenuButton&#39;);
<a name="line34"></a>goog.require(&#39;goog.ui.SelectionModel&#39;);
<a name="line35"></a>goog.require(&#39;goog.ui.registry&#39;);
<a name="line36"></a>
<a name="line37"></a>
<a name="line38"></a>
<a name="line39"></a>/**
<a name="line40"></a> * A selection control.  Extends {@link goog.ui.MenuButton} by composing a
<a name="line41"></a> * menu with a selection model, and automatically updating the button&#39;s caption
<a name="line42"></a> * based on the current selection.
<a name="line43"></a> *
<a name="line44"></a> * Select fires the following events:
<a name="line45"></a> *   CHANGE - after selection changes.
<a name="line46"></a> *
<a name="line47"></a> * @param {goog.ui.ControlContent} caption Default caption or existing DOM
<a name="line48"></a> *     structure to display as the button&#39;s caption when nothing is selected.
<a name="line49"></a> * @param {goog.ui.Menu=} opt_menu Menu containing selection options.
<a name="line50"></a> * @param {goog.ui.ButtonRenderer=} opt_renderer Renderer used to render or
<a name="line51"></a> *     decorate the control; defaults to {@link goog.ui.MenuButtonRenderer}.
<a name="line52"></a> * @param {goog.dom.DomHelper=} opt_domHelper Optional DOM hepler, used for
<a name="line53"></a> *     document interaction.
<a name="line54"></a> * @constructor
<a name="line55"></a> * @extends {goog.ui.MenuButton}
<a name="line56"></a> */
<a name="line57"></a>goog.ui.Select = function(caption, opt_menu, opt_renderer, opt_domHelper) {
<a name="line58"></a>  goog.ui.MenuButton.call(this, caption, opt_menu, opt_renderer, opt_domHelper);
<a name="line59"></a>  this.setDefaultCaption(caption);
<a name="line60"></a>  this.setPreferredAriaRole(goog.a11y.aria.Role.LISTBOX);
<a name="line61"></a>};
<a name="line62"></a>goog.inherits(goog.ui.Select, goog.ui.MenuButton);
<a name="line63"></a>
<a name="line64"></a>
<a name="line65"></a>/**
<a name="line66"></a> * The selection model controlling the items in the menu.
<a name="line67"></a> * @type {goog.ui.SelectionModel}
<a name="line68"></a> * @private
<a name="line69"></a> */
<a name="line70"></a>goog.ui.Select.prototype.selectionModel_ = null;
<a name="line71"></a>
<a name="line72"></a>
<a name="line73"></a>/**
<a name="line74"></a> * Default caption to be shown when no option is selected.
<a name="line75"></a> * @type {goog.ui.ControlContent}
<a name="line76"></a> * @private
<a name="line77"></a> */
<a name="line78"></a>goog.ui.Select.prototype.defaultCaption_ = null;
<a name="line79"></a>
<a name="line80"></a>
<a name="line81"></a>/** @override */
<a name="line82"></a>goog.ui.Select.prototype.enterDocument = function() {
<a name="line83"></a>  goog.ui.Select.superClass_.enterDocument.call(this);
<a name="line84"></a>  this.updateCaption();
<a name="line85"></a>  this.listenToSelectionModelEvents_();
<a name="line86"></a>  var selectElement = this.getElement();
<a name="line87"></a>  goog.asserts.assert(selectElement,
<a name="line88"></a>      &#39;The select DOM element cannot be null.&#39;);
<a name="line89"></a>  // Need to set HASPOPUP to false since it&#39;s set to true in the parent class.
<a name="line90"></a>  goog.a11y.aria.setState(selectElement, goog.a11y.aria.State.HASPOPUP,
<a name="line91"></a>      &#39;false&#39;);
<a name="line92"></a>};
<a name="line93"></a>
<a name="line94"></a>
<a name="line95"></a>/**
<a name="line96"></a> * Decorates the given element with this control.  Overrides the superclass
<a name="line97"></a> * implementation by initializing the default caption on the select button.
<a name="line98"></a> * @param {Element} element Element to decorate.
<a name="line99"></a> * @override
<a name="line100"></a> */
<a name="line101"></a>goog.ui.Select.prototype.decorateInternal = function(element) {
<a name="line102"></a>  goog.ui.Select.superClass_.decorateInternal.call(this, element);
<a name="line103"></a>  var caption = this.getCaption();
<a name="line104"></a>  if (caption) {
<a name="line105"></a>    // Initialize the default caption.
<a name="line106"></a>    this.setDefaultCaption(caption);
<a name="line107"></a>  } else {
<a name="line108"></a>    // There is no default caption; select the first option.
<a name="line109"></a>    this.setSelectedIndex(0);
<a name="line110"></a>  }
<a name="line111"></a>};
<a name="line112"></a>
<a name="line113"></a>
<a name="line114"></a>/** @override */
<a name="line115"></a>goog.ui.Select.prototype.disposeInternal = function() {
<a name="line116"></a>  goog.ui.Select.superClass_.disposeInternal.call(this);
<a name="line117"></a>
<a name="line118"></a>  if (this.selectionModel_) {
<a name="line119"></a>    this.selectionModel_.dispose();
<a name="line120"></a>    this.selectionModel_ = null;
<a name="line121"></a>  }
<a name="line122"></a>
<a name="line123"></a>  this.defaultCaption_ = null;
<a name="line124"></a>};
<a name="line125"></a>
<a name="line126"></a>
<a name="line127"></a>/**
<a name="line128"></a> * Handles {@link goog.ui.Component.EventType.ACTION} events dispatched by
<a name="line129"></a> * the menu item clicked by the user.  Updates the selection model, calls
<a name="line130"></a> * the superclass implementation to hide the menu, stops the propagation of
<a name="line131"></a> * the event, and dispatches an ACTION event on behalf of the select control
<a name="line132"></a> * itself.  Overrides {@link goog.ui.MenuButton#handleMenuAction}.
<a name="line133"></a> * @param {goog.events.Event} e Action event to handle.
<a name="line134"></a> * @override
<a name="line135"></a> */
<a name="line136"></a>goog.ui.Select.prototype.handleMenuAction = function(e) {
<a name="line137"></a>  this.setSelectedItem(/** @type {goog.ui.MenuItem} */ (e.target));
<a name="line138"></a>  goog.base(this, &#39;handleMenuAction&#39;, e);
<a name="line139"></a>
<a name="line140"></a>  // NOTE(user): We should not stop propagation and then fire
<a name="line141"></a>  // our own ACTION event. Fixing this without breaking anyone
<a name="line142"></a>  // relying on this event is hard though.
<a name="line143"></a>  e.stopPropagation();
<a name="line144"></a>  this.dispatchEvent(goog.ui.Component.EventType.ACTION);
<a name="line145"></a>};
<a name="line146"></a>
<a name="line147"></a>
<a name="line148"></a>/**
<a name="line149"></a> * Handles {@link goog.events.EventType.SELECT} events raised by the
<a name="line150"></a> * selection model when the selection changes.  Updates the contents of the
<a name="line151"></a> * select button.
<a name="line152"></a> * @param {goog.events.Event} e Selection event to handle.
<a name="line153"></a> */
<a name="line154"></a>goog.ui.Select.prototype.handleSelectionChange = function(e) {
<a name="line155"></a>  var item = this.getSelectedItem();
<a name="line156"></a>  goog.ui.Select.superClass_.setValue.call(this, item &amp;&amp; item.getValue());
<a name="line157"></a>  this.updateCaption();
<a name="line158"></a>};
<a name="line159"></a>
<a name="line160"></a>
<a name="line161"></a>/**
<a name="line162"></a> * Replaces the menu currently attached to the control (if any) with the given
<a name="line163"></a> * argument, and updates the selection model.  Does nothing if the new menu is
<a name="line164"></a> * the same as the old one.  Overrides {@link goog.ui.MenuButton#setMenu}.
<a name="line165"></a> * @param {goog.ui.Menu} menu New menu to be attached to the menu button.
<a name="line166"></a> * @return {goog.ui.Menu|undefined} Previous menu (undefined if none).
<a name="line167"></a> * @override
<a name="line168"></a> */
<a name="line169"></a>goog.ui.Select.prototype.setMenu = function(menu) {
<a name="line170"></a>  // Call superclass implementation to replace the menu.
<a name="line171"></a>  var oldMenu = goog.ui.Select.superClass_.setMenu.call(this, menu);
<a name="line172"></a>
<a name="line173"></a>  // Do nothing unless the new menu is different from the current one.
<a name="line174"></a>  if (menu != oldMenu) {
<a name="line175"></a>    // Clear the old selection model (if any).
<a name="line176"></a>    if (this.selectionModel_) {
<a name="line177"></a>      this.selectionModel_.clear();
<a name="line178"></a>    }
<a name="line179"></a>
<a name="line180"></a>    // Initialize new selection model (unless the new menu is null).
<a name="line181"></a>    if (menu) {
<a name="line182"></a>      if (this.selectionModel_) {
<a name="line183"></a>        menu.forEachChild(function(child, index) {
<a name="line184"></a>          this.setCorrectAriaRole_(
<a name="line185"></a>              /** @type {goog.ui.MenuItem|goog.ui.MenuSeparator} */ (child));
<a name="line186"></a>          this.selectionModel_.addItem(child);
<a name="line187"></a>        }, this);
<a name="line188"></a>      } else {
<a name="line189"></a>        this.createSelectionModel_(menu);
<a name="line190"></a>      }
<a name="line191"></a>    }
<a name="line192"></a>  }
<a name="line193"></a>
<a name="line194"></a>  return oldMenu;
<a name="line195"></a>};
<a name="line196"></a>
<a name="line197"></a>
<a name="line198"></a>/**
<a name="line199"></a> * Returns the default caption to be shown when no option is selected.
<a name="line200"></a> * @return {goog.ui.ControlContent} Default caption.
<a name="line201"></a> */
<a name="line202"></a>goog.ui.Select.prototype.getDefaultCaption = function() {
<a name="line203"></a>  return this.defaultCaption_;
<a name="line204"></a>};
<a name="line205"></a>
<a name="line206"></a>
<a name="line207"></a>/**
<a name="line208"></a> * Sets the default caption to the given string or DOM structure.
<a name="line209"></a> * @param {goog.ui.ControlContent} caption Default caption to be shown
<a name="line210"></a> *    when no option is selected.
<a name="line211"></a> */
<a name="line212"></a>goog.ui.Select.prototype.setDefaultCaption = function(caption) {
<a name="line213"></a>  this.defaultCaption_ = caption;
<a name="line214"></a>  this.updateCaption();
<a name="line215"></a>};
<a name="line216"></a>
<a name="line217"></a>
<a name="line218"></a>/**
<a name="line219"></a> * Adds a new menu item at the end of the menu.
<a name="line220"></a> * @param {goog.ui.Control} item Menu item to add to the menu.
<a name="line221"></a> * @override
<a name="line222"></a> */
<a name="line223"></a>goog.ui.Select.prototype.addItem = function(item) {
<a name="line224"></a>  this.setCorrectAriaRole_(
<a name="line225"></a>      /** @type {goog.ui.MenuItem|goog.ui.MenuSeparator} */ (item));
<a name="line226"></a>  goog.ui.Select.superClass_.addItem.call(this, item);
<a name="line227"></a>
<a name="line228"></a>  if (this.selectionModel_) {
<a name="line229"></a>    this.selectionModel_.addItem(item);
<a name="line230"></a>  } else {
<a name="line231"></a>    this.createSelectionModel_(this.getMenu());
<a name="line232"></a>  }
<a name="line233"></a>};
<a name="line234"></a>
<a name="line235"></a>
<a name="line236"></a>/**
<a name="line237"></a> * Adds a new menu item at a specific index in the menu.
<a name="line238"></a> * @param {goog.ui.MenuItem|goog.ui.MenuSeparator} item Menu item to add to the
<a name="line239"></a> *     menu.
<a name="line240"></a> * @param {number} index Index at which to insert the menu item.
<a name="line241"></a> * @override
<a name="line242"></a> */
<a name="line243"></a>goog.ui.Select.prototype.addItemAt = function(item, index) {
<a name="line244"></a>  this.setCorrectAriaRole_(
<a name="line245"></a>      /** @type {goog.ui.MenuItem|goog.ui.MenuSeparator} */ (item));
<a name="line246"></a>  goog.ui.Select.superClass_.addItemAt.call(this, item, index);
<a name="line247"></a>
<a name="line248"></a>  if (this.selectionModel_) {
<a name="line249"></a>    this.selectionModel_.addItemAt(item, index);
<a name="line250"></a>  } else {
<a name="line251"></a>    this.createSelectionModel_(this.getMenu());
<a name="line252"></a>  }
<a name="line253"></a>};
<a name="line254"></a>
<a name="line255"></a>
<a name="line256"></a>/**
<a name="line257"></a> * Removes an item from the menu and disposes it.
<a name="line258"></a> * @param {goog.ui.MenuItem|goog.ui.MenuSeparator} item The menu item to remove.
<a name="line259"></a> * @override
<a name="line260"></a> */
<a name="line261"></a>goog.ui.Select.prototype.removeItem = function(item) {
<a name="line262"></a>  goog.ui.Select.superClass_.removeItem.call(this, item);
<a name="line263"></a>  if (this.selectionModel_) {
<a name="line264"></a>    this.selectionModel_.removeItem(item);
<a name="line265"></a>  }
<a name="line266"></a>};
<a name="line267"></a>
<a name="line268"></a>
<a name="line269"></a>/**
<a name="line270"></a> * Removes a menu item at a given index in the menu and disposes it.
<a name="line271"></a> * @param {number} index Index of item.
<a name="line272"></a> * @override
<a name="line273"></a> */
<a name="line274"></a>goog.ui.Select.prototype.removeItemAt = function(index) {
<a name="line275"></a>  goog.ui.Select.superClass_.removeItemAt.call(this, index);
<a name="line276"></a>  if (this.selectionModel_) {
<a name="line277"></a>    this.selectionModel_.removeItemAt(index);
<a name="line278"></a>  }
<a name="line279"></a>};
<a name="line280"></a>
<a name="line281"></a>
<a name="line282"></a>/**
<a name="line283"></a> * Selects the specified option (assumed to be in the select menu), and
<a name="line284"></a> * deselects the previously selected option, if any.  A null argument clears
<a name="line285"></a> * the selection.
<a name="line286"></a> * @param {goog.ui.MenuItem} item Option to be selected (null to clear
<a name="line287"></a> *     the selection).
<a name="line288"></a> */
<a name="line289"></a>goog.ui.Select.prototype.setSelectedItem = function(item) {
<a name="line290"></a>  if (this.selectionModel_) {
<a name="line291"></a>    var prevItem = this.getSelectedItem();
<a name="line292"></a>    this.selectionModel_.setSelectedItem(item);
<a name="line293"></a>
<a name="line294"></a>    if (item != prevItem) {
<a name="line295"></a>      this.dispatchEvent(goog.ui.Component.EventType.CHANGE);
<a name="line296"></a>    }
<a name="line297"></a>  }
<a name="line298"></a>};
<a name="line299"></a>
<a name="line300"></a>
<a name="line301"></a>/**
<a name="line302"></a> * Selects the option at the specified index, or clears the selection if the
<a name="line303"></a> * index is out of bounds.
<a name="line304"></a> * @param {number} index Index of the option to be selected.
<a name="line305"></a> */
<a name="line306"></a>goog.ui.Select.prototype.setSelectedIndex = function(index) {
<a name="line307"></a>  if (this.selectionModel_) {
<a name="line308"></a>    this.setSelectedItem(/** @type {goog.ui.MenuItem} */
<a name="line309"></a>        (this.selectionModel_.getItemAt(index)));
<a name="line310"></a>  }
<a name="line311"></a>};
<a name="line312"></a>
<a name="line313"></a>
<a name="line314"></a>/**
<a name="line315"></a> * Selects the first option found with an associated value equal to the
<a name="line316"></a> * argument, or clears the selection if no such option is found.  A null
<a name="line317"></a> * argument also clears the selection.  Overrides {@link
<a name="line318"></a> * goog.ui.Button#setValue}.
<a name="line319"></a> * @param {*} value Value of the option to be selected (null to clear
<a name="line320"></a> *     the selection).
<a name="line321"></a> * @override
<a name="line322"></a> */
<a name="line323"></a>goog.ui.Select.prototype.setValue = function(value) {
<a name="line324"></a>  if (goog.isDefAndNotNull(value) &amp;&amp; this.selectionModel_) {
<a name="line325"></a>    for (var i = 0, item; item = this.selectionModel_.getItemAt(i); i++) {
<a name="line326"></a>      if (item &amp;&amp; typeof item.getValue == &#39;function&#39; &amp;&amp;
<a name="line327"></a>          item.getValue() == value) {
<a name="line328"></a>        this.setSelectedItem(/** @type {goog.ui.MenuItem} */ (item));
<a name="line329"></a>        return;
<a name="line330"></a>      }
<a name="line331"></a>    }
<a name="line332"></a>  }
<a name="line333"></a>
<a name="line334"></a>  this.setSelectedItem(null);
<a name="line335"></a>};
<a name="line336"></a>
<a name="line337"></a>
<a name="line338"></a>/**
<a name="line339"></a> * Returns the currently selected option.
<a name="line340"></a> * @return {goog.ui.MenuItem} The currently selected option (null if none).
<a name="line341"></a> */
<a name="line342"></a>goog.ui.Select.prototype.getSelectedItem = function() {
<a name="line343"></a>  return this.selectionModel_ ?
<a name="line344"></a>      /** @type {goog.ui.MenuItem} */ (this.selectionModel_.getSelectedItem()) :
<a name="line345"></a>      null;
<a name="line346"></a>};
<a name="line347"></a>
<a name="line348"></a>
<a name="line349"></a>/**
<a name="line350"></a> * Returns the index of the currently selected option.
<a name="line351"></a> * @return {number} 0-based index of the currently selected option (-1 if none).
<a name="line352"></a> */
<a name="line353"></a>goog.ui.Select.prototype.getSelectedIndex = function() {
<a name="line354"></a>  return this.selectionModel_ ? this.selectionModel_.getSelectedIndex() : -1;
<a name="line355"></a>};
<a name="line356"></a>
<a name="line357"></a>
<a name="line358"></a>/**
<a name="line359"></a> * @return {goog.ui.SelectionModel} The selection model.
<a name="line360"></a> * @protected
<a name="line361"></a> */
<a name="line362"></a>goog.ui.Select.prototype.getSelectionModel = function() {
<a name="line363"></a>  return this.selectionModel_;
<a name="line364"></a>};
<a name="line365"></a>
<a name="line366"></a>
<a name="line367"></a>/**
<a name="line368"></a> * Creates a new selection model and sets up an event listener to handle
<a name="line369"></a> * {@link goog.events.EventType.SELECT} events dispatched by it.
<a name="line370"></a> * @param {goog.ui.Component=} opt_component If provided, will add the
<a name="line371"></a> *     component&#39;s children as items to the selection model.
<a name="line372"></a> * @private
<a name="line373"></a> */
<a name="line374"></a>goog.ui.Select.prototype.createSelectionModel_ = function(opt_component) {
<a name="line375"></a>  this.selectionModel_ = new goog.ui.SelectionModel();
<a name="line376"></a>  if (opt_component) {
<a name="line377"></a>    opt_component.forEachChild(function(child, index) {
<a name="line378"></a>      this.setCorrectAriaRole_(
<a name="line379"></a>          /** @type {goog.ui.MenuItem|goog.ui.MenuSeparator} */ (child));
<a name="line380"></a>      this.selectionModel_.addItem(child);
<a name="line381"></a>    }, this);
<a name="line382"></a>  }
<a name="line383"></a>  this.listenToSelectionModelEvents_();
<a name="line384"></a>};
<a name="line385"></a>
<a name="line386"></a>
<a name="line387"></a>/**
<a name="line388"></a> * Subscribes to events dispatched by the selection model.
<a name="line389"></a> * @private
<a name="line390"></a> */
<a name="line391"></a>goog.ui.Select.prototype.listenToSelectionModelEvents_ = function() {
<a name="line392"></a>  if (this.selectionModel_) {
<a name="line393"></a>    this.getHandler().listen(this.selectionModel_, goog.events.EventType.SELECT,
<a name="line394"></a>        this.handleSelectionChange);
<a name="line395"></a>  }
<a name="line396"></a>};
<a name="line397"></a>
<a name="line398"></a>
<a name="line399"></a>/**
<a name="line400"></a> * Updates the caption to be shown in the select button.  If no option is
<a name="line401"></a> * selected and a default caption is set, sets the caption to the default
<a name="line402"></a> * caption; otherwise to the empty string.
<a name="line403"></a> * @protected
<a name="line404"></a> */
<a name="line405"></a>goog.ui.Select.prototype.updateCaption = function() {
<a name="line406"></a>  var item = this.getSelectedItem();
<a name="line407"></a>  this.setContent(item ? item.getCaption() : this.defaultCaption_);
<a name="line408"></a>};
<a name="line409"></a>
<a name="line410"></a>
<a name="line411"></a>/**
<a name="line412"></a> * Sets the correct ARIA role for the menu item or separator.
<a name="line413"></a> * @param {goog.ui.MenuItem|goog.ui.MenuSeparator} item The item to set.
<a name="line414"></a> * @private
<a name="line415"></a> */
<a name="line416"></a>goog.ui.Select.prototype.setCorrectAriaRole_ = function(item) {
<a name="line417"></a>  item.setPreferredAriaRole(item instanceof goog.ui.MenuItem ?
<a name="line418"></a>      goog.a11y.aria.Role.OPTION : goog.a11y.aria.Role.SEPARATOR);
<a name="line419"></a>};
<a name="line420"></a>
<a name="line421"></a>
<a name="line422"></a>/**
<a name="line423"></a> * Opens or closes the menu.  Overrides {@link goog.ui.MenuButton#setOpen} by
<a name="line424"></a> * highlighting the currently selected option on open.
<a name="line425"></a> * @param {boolean} open Whether to open or close the menu.
<a name="line426"></a> * @param {goog.events.Event=} opt_e Mousedown event that caused the menu to
<a name="line427"></a> *     be opened.
<a name="line428"></a> * @override
<a name="line429"></a> */
<a name="line430"></a>goog.ui.Select.prototype.setOpen = function(open, opt_e) {
<a name="line431"></a>  goog.ui.Select.superClass_.setOpen.call(this, open, opt_e);
<a name="line432"></a>
<a name="line433"></a>  if (this.isOpen()) {
<a name="line434"></a>    this.getMenu().setHighlightedIndex(this.getSelectedIndex());
<a name="line435"></a>  }
<a name="line436"></a>};
<a name="line437"></a>
<a name="line438"></a>
<a name="line439"></a>// Register a decorator factory function for goog.ui.Selects.
<a name="line440"></a>goog.ui.registry.setDecoratorByClassName(
<a name="line441"></a>    goog.getCssName(&#39;goog-select&#39;), function() {
<a name="line442"></a>      // Select defaults to using MenuButtonRenderer, since it shares its L&amp;F.
<a name="line443"></a>      return new goog.ui.Select(null);
<a name="line444"></a>    });
</pre>


</body>
</html>
